<script>
import ResourceList from "@/views/aihuman/log/Instance2D/ResourceList.vue";
import LogList from "@/views/aihuman/log/Instance2D/LogList.vue";
import {get2DServerInfo, resourceRelease} from "@/api/aihuman/log/log";

export default {
  name: "Instance2D",
  components: {LogList, ResourceList},
  data() {
    return {
      serverInfo: [],
      loading: false,
    }
  },
  created() {
    this.getSerInfo()
  },
  methods: {
    async getSerInfo() {
      this.loading = true
      const {data} = await get2DServerInfo()
      this.serverInfo = data.data
      this.loading = false
    },
    closeFn(row, item) {
      resourceRelease({
        resource_code: row.resource_code,
        serverId: item.serverInfo.id
      }).then(res=>{
        this.$message.success(res.data.msg)
      })
    }
  }
}
</script>

<template>
  <huilan-basic>
    <el-row v-for="(item , index) in serverInfo" :key="index" :gutter="20">
      <el-col :span="6">
        <div style="padding-bottom: 20px;">
          空闲资源：
          {{ item.resourceSlot.idle_slot }}/
          {{ item.resourceSlot.total_slot }}
        </div>
        <resource-list
          :data="item.runningList"
          v-loading="loading"
        />
      </el-col>
      <el-col :span="18">
        <div style="text-align: right;padding-bottom: 10px;">
          <el-button type="primary" size="small" icon="el-icon-refresh" @click="getSerInfo">刷新</el-button>
        </div>
        <log-list
          :data="item.applyList"
          v-loading="loading"
          @on-close="val=> closeFn(val, item)"
        />
      </el-col>
    </el-row>
  </huilan-basic>
</template>

<style scoped lang="scss">

</style>
